package cn.lingyangwl.agile.system.controller;

import cn.lingyangwl.agile.system.model.entity.SysPosition;
import cn.lingyangwl.agile.system.model.rqrs.position.*;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.agile.system.service.SysPositionService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shenguangyang
 */
@RestController
@RequestMapping("/position")
public class SysPositionController {
    @Resource
    private SysPositionService sysPositionService;

    @RamResource(action = "sys:position:list", name = "查询岗位列表", type = ActionType.READ)
    @GetMapping("/listAll")
    public Resp<List<SysPosition>> listAll() {
        List<SysPosition> list = sysPositionService.listAll();
        return Resp.ok(list);
    }

    @RamResource(action = "sys:position:get", name = "获取岗位详情", type = ActionType.READ)
    @GetMapping("/getById")
    public Resp<SysPosition> getPositionById(@RequestParam("id") Long id) {
        return Resp.ok(sysPositionService.getById(id));
    }

    @RamResource(action = "sys:position:list", name = "查询岗位列表", type = ActionType.READ)
    @GetMapping("/page")
    public Resp<IPage<SysPosition>> page(PositionQueryReq req) {
        IPage<SysPosition> page = sysPositionService.pagePosition(req);
        return Resp.ok(page);
    }

    @RamResource(action = "sys:position:save", name = "保存岗位", type = ActionType.WRITE)
    @PostMapping("/save")
    public Resp<?> save(@RequestBody SysPosition sysPosition) {
        sysPositionService.save(sysPosition);
        return Resp.ok();
    }

    @RamResource(action = "sys:position:update", name = "更新岗位", type = ActionType.WRITE)
    @PostMapping("/updateById")
    public Resp<?> updateById(SysPosition sysPosition) {
        sysPositionService.updateById(sysPosition);
        return Resp.ok();
    }

    @RamResource(action = "sys:position:delete", name = "删除岗位", type = ActionType.WRITE)
    @PostMapping("/deleteById")
    public Resp<?> deleteById(@RequestParam("id") Long id) {
        sysPositionService.deleteById(id);
        return Resp.ok();
    }
}